//
//  LGUtil.m
//  LoverGo
//
//  Created by YeXiao on 14-4-15.
//  Copyright (c) 2014年 yexiao. All rights reserved.
//

#import "LGUtil.h"
#import "UMSocialShakeService.h"
#import "UMSocialScreenShoter.h"
#import "UMSocialQQHandler.h"

@implementation LGUtil

+(UIView*)getLineView
{
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    return lineView;
}

+(CGRect)getViewFrame
{
    return CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
+ (UIBarButtonItem *)getBackButton
{
    UIBarButtonItem *bItem = [[UIBarButtonItem alloc] init];
    bItem.title = @"返回";
    [bItem setTintColor:[UIColor whiteColor]];
    return bItem;
}
+(UIButton*)get9ScalBtn:(CGRect)rect type:(TypeColor)type
{
    UIEdgeInsets insets1 = UIEdgeInsetsMake(10, 10, 9, 21);
    
    UIImage *s_Img = nil;
    UIImage *s_HImg = nil;
    switch (type) {
        case TypeColorOrange:
        {
            s_Img = [[UIImage imageNamed:@"ico_bluebtn.png"] resizableImageWithCapInsets:insets1];
            s_HImg = [[UIImage imageNamed:@"ico_article_pinkbn.9.png"] resizableImageWithCapInsets:insets1];
            break;
        }
        case TypeColorGreen:
        {
            s_Img = [[UIImage imageNamed:@"ico_popup_btn_bg.9.png"] resizableImageWithCapInsets:insets1];
            s_HImg = [[UIImage imageNamed:@"ico_darkbtn.9.png"] resizableImageWithCapInsets:insets1];
            
            break;
        }
        case TypeColorLogin:
        {
            s_Img = [[UIImage imageNamed:@"ico_article_pinkbn.9.png"] resizableImageWithCapInsets:insets1];
            s_HImg = [[UIImage imageNamed:@"dark_button_normal.9.png"] resizableImageWithCapInsets:insets1];
            break;
        }
        case TypeColorRegister:
        {
            s_Img = [[UIImage imageNamed:@"ico_bluebtn.png"] resizableImageWithCapInsets:insets1];
            s_HImg = [[UIImage imageNamed:@"dark_button_normal.9.png"] resizableImageWithCapInsets:insets1];
            break;
        }
            
        default:
            break;
    }
    
    UIButton *btn = [[UIButton alloc] initWithFrame:rect];
    [btn setBackgroundImage:s_Img forState:UIControlStateNormal];
    [btn setBackgroundImage:s_HImg forState:UIControlStateHighlighted];
    return btn;
}
+(UIImage*)get9ScalImg:(TypeImg)type
{
    UIImage *img = nil;
    switch (type) {
        case TypeImgBG:
            img = [[UIImage imageNamed:@"setting_lab_bg.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(13, 3, 13, 3)];
            break;
            
        default:
            break;
    }
    return img;
}
+ (UIImage *)getUnFoundImage
{
    return [UIImage imageNamed:@"img_default.png"];
}

+ (UIButton *)getBackBtn
{
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 72/2., 77/2.)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"info_city_close_btn_n.png"] forState:UIControlStateNormal];
    return backBtn;
}
+(UIButton*)returnLeftBtn
{
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60/2., 60/2.)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"btn_back_pressed.png"] forState:UIControlStateSelected];
    return backBtn;
}

+ (UIButton *)returnRightBtn
{
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44/2., 46/2.)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"more_button_up.png"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"more_button_down.png"] forState:UIControlStateHighlighted];
    return backBtn;
}
+(void)setTypeWithC:(UIViewController*)con titleName:(NSString *)tName backName:(NSString *)bName
{
    if (tName != nil)
    {
        UILabel *label = [[UILabel alloc] init];
        label.text = tName;
        [LGUtil setTitleLab:label];
        con.navigationItem.titleView = label;
    }
    if (bName != nil)
    {
        con.navigationItem.backBarButtonItem = [LGUtil getBackButton];
//        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
//        backItem.title = bName;
//        [backItem setTintColor:[UIColor whiteColor]];
//        con.navigationItem.backBarButtonItem = backItem;
    }
}
+ (void)setTitleLab:(UILabel *)lab
{
    [lab setFrame:CGRectZero];
    lab.backgroundColor = [UIColor clearColor];
    lab.font = [UIFont boldSystemFontOfSize:18.0];
    lab.textAlignment = NSTextAlignmentCenter;
    lab.textColor = [UIColor whiteColor];
    [lab sizeToFit];
}
+(UINavigationController *)getNavByType:(NavType)type controller:(UIViewController *)con
{
    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:con];
    //自定义tabBarItem
    UITabBarItem *tabBarItem = [[UITabBarItem alloc]init];
    [tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:102/255.0 green:221/255.0 blue:225/255.0 alpha:1],NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
    [navC.navigationBar setBarTintColor:[UIColor colorWithRed:102.0/255.0f green:221.0/255.0f blue:225.0/255.0f alpha:100]];
    navC.tabBarItem = tabBarItem;
    navC.navigationBar.translucent = NO;//半透明有光泽
    //自定义标题
    UILabel *label = [[UILabel alloc] init];
    navC.navigationBar.topItem.titleView=label;
    switch (type) {
        case TypeTuiJian:
        {
            tabBarItem.image  = [UIImage imageNamed:@"maintab_search.png"];
            //后面那句就让图片能正常显示了
            tabBarItem.selectedImage = [[UIImage imageNamed:@"maintab_search_selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            tabBarItem.title = @"推荐";
            label.text = @"推荐";
            break;
        }
        case TypeShouCang:
        {
            tabBarItem.image  = [UIImage imageNamed:@"maintab_home.png"];
            tabBarItem.selectedImage = [[UIImage imageNamed:@"maintab_home_selected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            tabBarItem.title = @"收藏";
            label.text = @"收藏";
            break;
        }
        case TypeGeRen:
        {
            tabBarItem.image  = [UIImage imageNamed:@"maintab_setting.png"];
            tabBarItem.selectedImage = [[UIImage imageNamed:@"maintab_setting_selected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            tabBarItem.title = @"个人";
            label.text = @"个人中心";
            break;
        }
            
        default:
            break;
    }
     
    [LGUtil setTitleLab:label];
    return navC;
}
+(UILabel*)getTitleLab:(CGRect)rect title:(NSString *)str
{
    UILabel *titleLab = [[UILabel alloc] initWithFrame:rect];
    [titleLab setBackgroundColor:[UIColor colorWithRed:240/255. green:100/255. blue:10/255. alpha:255]];
    [titleLab setShadowColor:[UIColor grayColor]];
    [titleLab setFont:[UIFont fontWithName:@"Helvetica" size:22]];
    [titleLab setShadowOffset:CGSizeMake(0.5, 0.5)];
    [titleLab setTextColor:[UIColor whiteColor]];
    [titleLab setText:str];
    [titleLab setTextAlignment:NSTextAlignmentCenter];
    return titleLab;
}
//判断number是否符合要求
+(BOOL)judgeNumber:(NSString *)_number{
    NSString *phoneCheck=@"^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
    NSPredicate *phonelTest=[NSPredicate predicateWithFormat:@"SELF MATCHES%@",phoneCheck];
    return [phonelTest evaluateWithObject:_number];
    
}
+ (void)shareToSNSURL:(NSString*)url title:(NSString*)title img:(UIImage*)img content:(NSString*)content controller:(UIViewController*)c
{
    //分享
    //UMSocialWXMessageTypeImage 为纯图片类型
    [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
    //分享图文样式到微信朋友圈显示字数比较少，只显示分享标题
    [UMSocialData defaultData].extConfig.title = title;
    //设置微信好友或者朋友圈的分享url,下面是微信好友，微信朋友圈对应wechatTimelineData
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = url;
    [UMSocialData defaultData].extConfig.wechatSessionData.url = url;
    
    
    [UMSocialData defaultData].extConfig.qqData.url = url;
    [UMSocialData defaultData].extConfig.qzoneData.url = url;
    
    //设置QQ
    
    [UMSocialSnsService presentSnsIconSheetView:c
                                         appKey:UmengAppkey
                                      shareText:content
                                     shareImage:img
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite,UMShareToQQ,UMShareToQzone,nil]
                                       delegate:nil];
}
@end
